Skip to content

feat(test): mypyc tests for container creation from range #19511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

BobTheBuidler
Copy link
Contributor

@BobTheBuidler BobTheBuidler commented Jul 25, 2025

This PR only adds tests to the existing suite.

I will be using them to ensure the quality of a future PR.

@BobTheBuidler BobTheBuidler changed the title feat(test): add mypyc tests for container creation from range feat(test): mypyc tests for container creation from range Jul 25, 2025
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The volume of these tests seems too much -- they seem to add about 5% to the total line count of irbuild tests, and the use case isn't very common.

We don't normally use irbuild tests to check lots of edge cases/variants -- we use them to make sure the quality of code for common or tricky use cases doesn't regress. When IR is changed, irbuild tests often need changes as well, and if too many irbuild tests need to be changed, reviewers are not likely to pay much attention to them and regressions are more likely to go unnoticed.

However, adding many of these as run tests would be reasonable, since they don't require much maintenance, and if run tests are added as additional def test_... cases to an existing test case, they won't slow down tests much. Top-level run tests indicated by [case ...] are quite slow and thus we try to group multiple related tests together, but adding additional cases to an existing [case ...] doesn't cause much slowdown.

@@ -113,3 +113,237 @@ L0:
r5 = r4 >= 0 :: signed
r6 = truncate r4: i32 to builtins.bool
return r6

[case testFrozenSetFromRange1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frozenset(range(...)) seems very rare. Do you have evidence that it's a bottleneck in some real-world codebase? If not, it would be sufficient to add a run test (as part of an existing run test to avoid slowing down the test suite), since irbuild tests require more maintenance.


[case testTupleFromRange1]
def fn() -> tuple[int, ...]:
return tuple(range(3))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above, tuple(range(...)) seems very rare (based on a large codebase I have access to -- there were no instance of it). Again, having run tests seems sufficient since irbuild tests are verbose and take some maintenance, preferable added to an existing run test.

If you create a PR that optimizes this, I wouldn't spend extra effort on tuple specifically, but if an optimization also benefits tuples, it would be enough to have some example IR dumps for relevant code in the PR summary.

@@ -573,6 +573,228 @@ L0:
r0 = CPySequence_Sort(a)
return 1

[case testListFromRange1]
def fn() -> list[int]:
return list(range(3))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list(range(...)) seems to be by far the most common of these use cases, so having some irbuild tests for them seems reasonable.

[case testListFromRange4]
def fn() -> list[str]:
abc = tuple(range(3))
return list(str(i) for i in abc)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels too specific for an irbuild test -- again, can you move this to be a run test?

[case testListFromRange5]
def fn() -> list[str]:
abc = tuple(range(1, 3))
return list(str(i) for i in abc)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another test that feels pretty specific. Do you have some real-world use case in mind?

[case testListFromRange6]
def fn() -> list[str]:
abc = tuple(range(1, 3, 2))
return list(str(i) for i in abc)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above.

@@ -799,3 +799,228 @@ L4:
r11 = CPy_NoErrOccurred()
L5:
return 1

[case testSetFromRange1]
def fn() -> set[int]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to find some example of set(range(...)), but only a few. I think the first two irbuild test cases are sufficient, due to maintainability concerns. These would be reasonable as run tests (preferable as new cases in an existing test case).

@JukkaL
Copy link
Collaborator

JukkaL commented Aug 15, 2025

In the past we've deleted some irbuild tests, since their maintenance took surprisingly lot of effort, and that's why I think it's better to have most things tested using run tests. Performance issues can also be tested using benchmarks (https://github.com/mypyc/mypyc-benchmarks), but they are also quite a heavy tool so they only work for the most common cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants